import BasicArray from "./BasicArray.js";

// 测试用例 1
let testList = [
    () => {
        // 1. 构造函数
        console.log("Test 1: 构造函数测试")
        let basicArray = new BasicArray(4);
        if (basicArray.size() !== 0) {
            return false;
        }
        if (basicArray.capacity() !== 4) {
            return false;
        }

        basicArray = new BasicArray();
        if (basicArray.size() !== 0) {
            return false;
        }
        if (basicArray.capacity() !== 10) {
            return false;
        }
        return true;
    },
    () => {
        // 2. 测试插入
        console.log("Test 2: 测试插入")
        let basicArray = new BasicArray(4);
        for (let i = 0; i < 4; i += 1) {
            if (!basicArray.insert(i, i)) {
                return false;
            }
            if (basicArray.size() !== (i + 1)) {
                return false;
            }
            if (basicArray.insert(i, 15)) {
                return false;
            }
        }

        if (basicArray.insert(0, 4)) {
            return false;
        }

        let arr = basicArray.getArray();
        for (let i = 0; i < 4; i += 1) {
            if (arr[i] !== i) {
                return false;
            }
        }
        return true;
    },
    () => {
        // 3. 测试删除
        console.log("Test 3: 测试删除")
        let basicArray = new BasicArray(4);
        for (let i = 0; i < 4; i += 1) {
            basicArray.insert(i, i);
        }
        if (!basicArray.remove(2)) {
            return false;
        }
        if (basicArray.remove(5)) {
            return false;
        }
        if (basicArray.size() !== 3) {
            return false;
        }
        let arr = basicArray.getArray();
        if (arr[2] !== 3) {
            return false;
        }
        for (let i = 0; i < 3; i += 1) {
            if (!basicArray.remove(0)) {
                return false;
            }
        }
        if (basicArray.remove(0)) {
            return false;
        }
        return true;
    }
]

let count = 0;
testList.forEach((test, index) => {
    if (test()) {
        console.log(`Test ${index + 1} 通过`);
        count += 1;
    } else {
        console.log(`Test ${index + 1} 失败`);
    }
})

console.log(`${count}/${testList.length} 测试通过`);